package com.example.jspweb.model;

import lombok.Data;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class LocationDto {
    private double x;
    private double y;

    /**
     * 计算当前位置到目标位置的直线距离
     * 使用欧几里得距离公式: √[(x₁-x₂)² + (y₁-y₂)²]
     *
     * @param target 目标位置
     * @return 两点之间的直线距离
     */
    public double distanceTo(LocationDto target) {
        double dx = this.x - target.x;
        double dy = this.y - target.y;
        return Math.sqrt(dx * dx + dy * dy);
    }
}
